package reduce.fz.com.reduce.util.base;

import android.content.Context;
import android.content.SharedPreferences;


public class PreferenceUtil {

    private static final String CONFIG_FILE_NAME = "feel_prefs";

    public static final String LOCATION_CACHE_KEY = "last_location";


    private static SharedPreferences getSharedPrefs() {
        return ReduceApplication.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
    }

    public static int getIntPreference(String key, int defaultVal) {
        return ReduceApplication.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE).getInt(key, defaultVal);
    }

    public static void saveIntPreference(String key, int value) {
        SharedPreferences.Editor editor = ReduceApplication.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE).edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public static long getLongPreferences(String key, long defaultVal) {
        return ReduceApplication.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE).getLong(key, defaultVal);
    }

    public static void saveLongPreference(String key, long value) {
        SharedPreferences.Editor editor = ReduceApplication.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE).edit();
        editor.putLong(key, value);
        editor.commit();
    }

    public static boolean getBoolPreference(String key) {
        return ReduceApplication.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE).getBoolean(key, false);
    }

    public static void saveBoolPreference(String key, boolean value) {
        SharedPreferences.Editor editor = ReduceApplication.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE).edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public static String getStringPreference(String key) {
        return ReduceApplication.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE).getString(key, "");
    }

    public static void saveStringPreference(String key, String value) {
        SharedPreferences.Editor editor = ReduceApplication.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE).edit();
        editor.putString(key, value);
        editor.commit();
    }
}
